import request from '@/axios'
import { DepartmentSaveData, DepartmentPageParams, DepartmentItem } from './types'

export const getDepartmentApi = (): Promise<IResponse<DepartmentItem[]>> => {
  return request.get({ url: '/departments/all' })
}

export const getSelfDepartmentApi = (): Promise<IResponse<DepartmentItem[]>> => {
  return request.get({ url: '/departments/all/self' })
}

export const createDepartmentApi = (data: DepartmentSaveData): Promise<IResponse> => {
  return request.post({ url: '/departments/create', data })
}

export const updateDepartmentApi = (data: DepartmentSaveData): Promise<IResponse> => {
  return request.put({ url: `/departments/update/${data.id}`, data })
}

export const deleteDepartmentApi = (ids: number[]): Promise<IResponse> => {
  return request.delete({ url: `/departments/delete/${ids.join(',')}` })
}

export const getDepartmentDetailApi = (id: number): Promise<IResponse<DepartmentItem>> => {
  return request.get({ url: `/departments/detail/${id}` })
}

export const getDepartmentTableApi = (
  params: DepartmentPageParams
): Promise<IResponse<DepartmentItem[]>> => {
  return request.get({ url: '/departments/page', params })
}
